package com.example.homework.dao;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.homework.Constants;

/**
 * @作者 zhaichenji
 * @创建日期 2022/4/10 19:14
 * @包名 com.example.homework.Dao
 * @版本 1.0
 * @描述 用户在登录时，进行用户名密码验证
 */
public class LoginDao extends MySQLiteOpenHelper{

    public Context context;
    public LoginDao(Context context) {
        super(context);
    }

    /**
     * 用户登录时对用户名密码进行验证
     * @param username
     * @param password
     * @return
     */
    public boolean loginValidate(String username,String password){
        SQLiteDatabase db = getWritableDatabase();
        String QUERY_USER_EXIST = "select * from "+ Constants.TABLE_NAME_USER+" where username=? and password=?;";

        Cursor cursor = db.rawQuery(QUERY_USER_EXIST, new String[]{username, password});
        while (cursor.moveToNext()){
            return true;
        }
        return false;
    }
}
